<?php
namespace app\mogo\model;

use think\Model;
use traits\model\SoftDelete;

class Comments extends Model
{
    use SoftDelete;
    protected $table = 'dp_mogo_comments';
    protected $autoWriteTimestamp = true;
    protected $insert = ['user_id'=>MOGO_ID];


    public function comments(){
        return $this->hasMany('Comments')->order('id desc');
    }

    public function user(){
        return $this->belongsTo(config('user_model'))->field([
            config('user_filed.nickname'),
            config('user_filed.avatar'),
            config('user_table').'.id'
        ]);
    }

    public function like(){
        return $this->belongsToMany('User','mogo_like')->field([
            config('user_filed.nickname'),
            config('user_filed.avatar'),
            config('user_table').'.id'
        ]);
    }
    public function checkIsLike($user_id=MOGO_ID){
        return $this->like()->where('user_id',$user_id)->count();
    }
}
